package com.feisuanyz.controller;

import com.feisuanyz.dto.EventValidationQuery;
import com.feisuanyz.dto.LogoValidationQuery;
import com.feisuanyz.dto.NotificationValidationQuery;
import com.feisuanyz.dto.RestResult;
import com.feisuanyz.dto.TicketValidationQuery;
import com.feisuanyz.service.validation.EventValidationService;
import com.feisuanyz.service.validation.LogoValidationService;
import com.feisuanyz.service.validation.NotificationValidationService;
import com.feisuanyz.service.validation.TicketValidationService;
//import javax.validation.Valid;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 验证控制器
 */
@RestController
@RequestMapping("/validation")
//@Slf4j
@Validated
public class ValidationController {

    @Autowired
    private EventValidationService eventValidationService;

    @Autowired
    private TicketValidationService ticketValidationService;

    @Autowired
    private NotificationValidationService notificationValidationService;

    @Autowired
    private LogoValidationService logoValidationService;

    @PostMapping("/event")
    public ResponseEntity<RestResult> validateEvent(@Valid @RequestBody EventValidationQuery query) {
        RestResult result = eventValidationService.validateEvent(query, "create");
        return ResponseEntity.ok(result);
    }

    @PutMapping("/event")
    public ResponseEntity<RestResult> editEvent(@Valid @RequestBody EventValidationQuery query) {
        RestResult result = eventValidationService.validateEvent(query, "edit");
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/event/{eventId}")
    public ResponseEntity<RestResult> deleteEvent(@PathVariable Integer eventId) {
        EventValidationQuery query = new EventValidationQuery();
        query.setEventId(eventId);
        RestResult result = eventValidationService.validateEvent(query, "delete");
        return ResponseEntity.ok(result);
    }

    @PostMapping("/ticket")
    public ResponseEntity<RestResult> validateTicket(@Valid @RequestBody TicketValidationQuery query) {
        RestResult result = ticketValidationService.validateTicket(query, "create");
        return ResponseEntity.ok(result);
    }

    @PutMapping("/ticket")
    public ResponseEntity<RestResult> editTicket(@Valid @RequestBody TicketValidationQuery query) {
        RestResult result = ticketValidationService.validateTicket(query, "edit");
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/ticket/{ticketId}")
    public ResponseEntity<RestResult> deleteTicket(@PathVariable Integer ticketId) {
        TicketValidationQuery query = new TicketValidationQuery();
        query.setTicketId(ticketId);
        RestResult result = ticketValidationService.validateTicket(query, "delete");
        return ResponseEntity.ok(result);
    }

    @PostMapping("/notification")
    public ResponseEntity<RestResult> validateNotification(@Valid @RequestBody NotificationValidationQuery query) {
        RestResult result = notificationValidationService.validateNotification(query, "create");
        return ResponseEntity.ok(result);
    }

    @PutMapping("/notification")
    public ResponseEntity<RestResult> editNotification(@Valid @RequestBody NotificationValidationQuery query) {
        RestResult result = notificationValidationService.validateNotification(query, "edit");
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/notification/{notificationId}")
    public ResponseEntity<RestResult> deleteNotification(@PathVariable Integer notificationId) {
        NotificationValidationQuery query = new NotificationValidationQuery();
        query.setNotificationId(notificationId);
        RestResult result = notificationValidationService.validateNotification(query, "delete");
        return ResponseEntity.ok(result);
    }

    @PostMapping("/logo")
    public ResponseEntity<RestResult> validateLogo(@Valid @RequestBody LogoValidationQuery query) {
        RestResult result = logoValidationService.validateLogo(query, "create");
        return ResponseEntity.ok(result);
    }

    @PutMapping("/logo")
    public ResponseEntity<RestResult> editLogo(@Valid @RequestBody LogoValidationQuery query) {
        RestResult result = logoValidationService.validateLogo(query, "edit");
        return ResponseEntity.ok(result);
    }

    @DeleteMapping("/logo/{logoId}")
    public ResponseEntity<RestResult> deleteLogo(@PathVariable Integer logoId) {
        LogoValidationQuery query = new LogoValidationQuery();
        query.setLogoId(logoId);
        RestResult result = logoValidationService.validateLogo(query, "delete");
        return ResponseEntity.ok(result);
    }
}